package com.hjm.ui.home.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hjm.ui.R;

import java.util.List;


public class HomeNavAdapter extends RecyclerView.Adapter<HomeNavAdapter.ViewHolder> {
    private List<? extends Nav> navList;
    private Context context;
    private OnclickListener onclickListener;
    public HomeNavAdapter(List<? extends Nav> navList,OnclickListener onclickListener, Context context) {
        this.navList = navList;
        this.context = context;
        this.onclickListener = onclickListener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_nav, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Nav nav = navList.get(position);
//        holder.image.setImageDrawable(nav.getImg());
        holder.image.setImageBitmap(nav.getBitmap());
        holder.title.setText(nav.getTitle());
        holder.view.setOnClickListener(v->{
            onclickListener.onclick(nav.getId());
        });
    }

    @Override
    public int getItemCount() {
        return navList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView image;
        TextView title;
        View view;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view = itemView;
            image = itemView.findViewById(R.id.image);
            title = itemView.findViewById(R.id.title);
        }
    }

    public static class Nav {
        Integer id;
        String title;
        Drawable img;
        Bitmap bitmap;

        public Nav(String title, Drawable img) {
            this.title = title;
            this.img = img;
        }

        public Nav() {

        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public Drawable getImg() {
            return img;
        }

        public void setImg(Drawable img) {
            this.img = img;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public Bitmap getBitmap() {
            return bitmap;
        }

        public void setBitmap(Bitmap bitmap) {
            this.bitmap = bitmap;
        }
    }

    public interface OnclickListener {
        void onclick(Integer id);
    }
}